<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui">
<h:head>
	<title>Demo</title>
	<h:outputStylesheet name="style.css" library="css"></h:outputStylesheet>
	<script>
	function onDelete(){
		if(confirm('Are you sure?')){
			return true;
		} else return false;
	}
	</script>
</h:head>
<h:body>
	<div class="main-content">
		<br/>
		<h1>ELI UPDATE CENTER</h1>
		<br/>
		<f:event type="postAddToView" listener="#{getData.onload}" />
		<h:form id="form1">
			<table class="main-table">
				<tr>
					<th>ID</th>
					<th>Application Name</th>
					<th>Package</th>
					<th>Size (KB)</th>
					<th>Version Name</th>
					<th>Version Code</th>
					<th>Last Update</th>
				</tr>
				<ui:repeat var="item" value="#{getData.listItem}">
					<tr>
						<td><h:outputText value="#{item.id}" /></td>
						<td><h:commandLink value="#{item.name}"
								actionListener="#{getData.select}">
								<f:attribute name="item" value="#{item}"></f:attribute>
							</h:commandLink>
						</td>
						<td><h:outputText value="#{item.packageName}" /></td>
						<td><h:outputText value="#{item.size}" /></td>
						<td><h:outputText value="#{item.version}" /></td>
						<td><h:outputText value="#{item.version_code}" /></td>
						<td><h:outputText value="#{item.lastUpdate}" /></td>
					</tr>
				</ui:repeat>
			</table>
			<br />
			<h:commandButton value="Create New App" action="#{getData.create}" rendered="#{getData.action == 'update' or getData.action==''}"/>
			<br />
		</h:form>
		<h:form enctype="multipart/form-data">
			<p:messages showDetail="true"/> 
			<h:panelGroup id="formUpdate"
				rendered="#{getData.action == 'update' or getData.action=='create'}">
				<div class="input-panel">
					<table class="input-table">
						<tr>
							<td class="input-table-first">Application Name</td>
							<td><h:inputText value="#{getData.item.name}" /></td>
						</tr>
						<tr>
							<td class="input-table-first">Package Name</td>
							<td><h:inputText value="#{getData.item.packageName}" /></td>
						</tr>
						<tr>
							<td class="input-table-first">Version Name</td>
							<td><h:inputText value="#{getData.item.version}" /></td>
						</tr>
						<tr>
							<td class="input-table-first">Version Code</td>
							<td><h:inputText value="#{getData.item.version_code}" /></td>
						</tr>
						<tr>
							<td class="input-table-first">Description</td>
							<td><h:inputTextarea value="#{getData.item.description}" />
							</td>
						</tr>
						<tr>
							<td class="input-table-first">Upload</td>
							<td><p:fileUpload value="#{getData.fileUpload}"
									mode="simple" />
							</td>
						</tr>
						<tr>
							<td></td>
							<td><h:commandButton value="Update Only Information"
									action="#{getData.update}"
									rendered="#{getData.action == 'update'}" />
								<h:commandButton
									value="Update All" action="#{getData.uploadFile}" />
								<h:commandButton onclick="return onDelete();"
									value="Delete" action="#{getData.delete}" rendered="#{getData.action == 'update'}"/>
								<h:commandButton
									value="Cancel" action="#{getData.cancel}" /></td>
						</tr>
					</table>
				</div>
			</h:panelGroup>
		</h:form>

	</div>
</h:body>
</html>